//
//  UIBatButtonItem+Extension.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/3.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageNamed:String? = nil,title:String? = nil, target:AnyObject? ,action:Selector) {
        self.init()
        
        let button = UIButton()
        
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let t = title {
            
            button.setTitle(t, forState: UIControlState.Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.setTitleColor(UIColor(colorLiteralRed: 52/255, green: 52/255, blue: 52/255, alpha: 1), forState: .Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(14)
        }
        if let named = imageNamed {
            
            button.setImage(UIImage(named: named), forState: UIControlState.Normal)
            button.setImage(UIImage(named: "\(named)_highlighted"), forState: UIControlState.Highlighted)
        }
        button.sizeToFit()
        customView = button
        
    }
    
    
    
    
    
    
    
    
    
    
}
